import type { NuxtAxiosInstance } from "@nuxtjs/axios"



export default ($axios: NuxtAxiosInstance) => {
    return {
        /**
         * 获取文章列表中的页面数据
         * @returns 
         */
        articlePage: (params: { [key: string]: any }) => {
            return $axios({
                url: '/client/articlePage',
                method: 'get',
                params,
            })
        },

        /**
         * 查询标签列表 id 文章id
         * @returns 
         */
        articleByIdPage: (params: { id: string | number }) => {
            return $axios({
                url: '/client/articleByIdPage',
                method: 'get',
                params,
            })
        },

         /**
         * 查询标签页
         * @returns 
         */
         tagsPage: () => {
            return $axios({
                url: `/client/tagsPage`,
                method: 'get'
            })
        },

        /**
         * 查询标签详情页通过标签id
         * @returns 
         */
        tagByIdPage: (params: { tagId: number }) => {
            return $axios({
                url: `/client/tagByIdPage`,
                method: 'get',
                params
            })
        },

        /**
         * 新增文章评论
         * @returns 
         */
        inserArticleComment: (params: { [key: string]: any }) => {
            const formData = new FormData()
            Object.entries(params).forEach(([key, value]) => {
                if (key !== 'file' || (key === 'file' && value)) {
                    formData.append(key, value)   
                }
            })
            return $axios({
                url: `/client/inserArticleComment`,
                method: 'post',
                data: formData,
                headers: {
                    ContentType: 'multipart/form-data;'
                }
            })
        },
        
        // /**
        //  * 通过文章id查询评论内容
        //  * @returns 
        //  */
        // articleComment: (params: { tagId: number }) => {
        //     return $axios({
        //         url: `/client/articleComment`,
        //         method: 'get',
        //         params
        //     })
        // },

        
    }
}